<?php

/**
 * @Author: Mr.Mao
 * @Date:   2021-08-02 13:45:16
 * @Last Modified by:   Mr.Mao
 * @Last Modified time: 2021-11-18 14:09:52
 */
namespace app\publics\controller\api;
use app\ApiController;
use app\member\model\WithdrawLogModel;
use app\shop\model\OrderModel;
use app\member\model\UsersModel;
use app\distribution\model\DividendAwardModel;
use app\distribution\model\DividendModel;
use app\member\model\AccountModel;
use think\Db;
use think\facade\Cache;
/*------------------------------------------------------ */
//-- 文章
/*------------------------------------------------------ */
class Profit extends ApiController
{
	/*------------------------------------------------------ */
    //-- 优先执行
    /*------------------------------------------------------ */
    public function initialize()
    {
        parent::initialize();
        $this->Model = new DividendModel();
        $this->AccountModel = new AccountModel();
    }
    /**
     * [每日冻积分释放]
     * @return [type] [description]
     */
    public function callback()
    {
        file_put_contents('/www/wwwroot/ldcs.zhihui888.cn/public/profit.log',json_encode(input())."\r\n",8);
        $data = input();
        $model = new WithdrawLogModel();
        $info = $model->where('order_sn',$data['order_sn'])->find();
        $AccountModel = new AccountModel();
        if($info){
            if($data['status'] != 2){
                $res = $model->where('order_sn',$data['order_sn'])->update(['status' => 1,'admin_note' => $data['error_msg']]);
                if($res){
                    $changedata['change_desc'] = '提现失败退回';
                    $changedata['change_type'] = 5;
                    $changedata['by_id'] = $info['log_id'];
                    $changedata['balance_money'] = $info['fee_type']==0?($info['money'] + $info['withdraw_fee']):$info['money'];
                    $AccountModel->change($changedata, $info['user_id'], false);
                }
            }
            echo 'success';exit;
        }

    }

}
